package com.gx.project.base.service;

import com.gx.common.result.ResponsePageResult;
import com.gx.common.result.ResponseResult;
import com.gx.project.base.dao.BaseDao;
import com.gx.project.base.domain.BaseDomain;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * Created by Administrator on 2017/9/6.
 */
public abstract class AbstractBaseService<T, C> implements BaseService<T, C> {

    @Override
    public T getById(C id) {
        return getBaseDomain().getById(id);
    }

    @Override
    public ResponsePageResult getListByPage(Map<String, Object> params, Integer pageNo, Integer pageSize) {
        ResponsePageResult rp = ResponsePageResult.empty(pageNo == null ? 0 : pageNo, pageSize == null ? 0 : pageSize);
        Map<String, Object> getListByPage = getBaseDomain().getListByPage(params, pageNo, pageSize);
        rp.setTotalCount((Integer) getListByPage.get("total"));
        rp.setData(getListByPage.get("data"));
        return rp;
    }

    @Override
    public Boolean removeById(C id) {
        return getBaseDomain().removeById(id);
    }

    protected abstract BaseDomain<T, C> getBaseDomain();
}
